package com.mobilous.client.project.pagemanager;

import java.util.ArrayList;

import org.vaadin.gwtgraphics.client.DrawingArea;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.TextBox;
import com.mobilous.client.project.PageOutline;

public class PageName extends DialogBox {
	public PageName(final PageOutline create, final ArrayList<PageOutline> pages, final DrawingArea canvas, final Image image) {
		
		setHTML("Page name and Link");
		
		AbsolutePanel absolutePanel = new AbsolutePanel();
		setWidget(absolutePanel);
		absolutePanel.setSize("218px", "155px");
		
		final Label lblPageName = new Label("Page Name");
		absolutePanel.add(lblPageName, 10, 10);
		
		final TextBox textBox = new TextBox();
		absolutePanel.add(textBox, 10, 34);
		textBox.setSize("184px", "18px");
		
		Button btnDonr = new Button("Donr");
		btnDonr.setText("Done");
		absolutePanel.add(btnDonr, 158, 118);
		
		Label lblLinkTo = new Label("Link To:");
		absolutePanel.add(lblLinkTo, 10, 70);
		
		final ListBox comboBox = new ListBox();
		if(pages.size()==0)		comboBox.addItem("Start Page");
		
		for(int i=0;i<pages.size();i++)
		{
			comboBox.addItem(pages.get(i).lblPagename.getText());
		}

		
		absolutePanel.add(comboBox, 10, 92);
		comboBox.setSize("194px", "20px");
		btnDonr.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				ApplicationPages.pagenamedialog.hide();
				create.lblPagename.setText(textBox.getText());
				LineLink obj;
				if(comboBox.getValue(comboBox.getSelectedIndex()).equalsIgnoreCase("Start Page"))
					obj = new LineLink(create, image, canvas);
				else 
					obj = new LineLink(create, pages.get(comboBox.getSelectedIndex()), canvas);
				create.link=obj;
			}});
	}
}
